#!/usr/bin/env python
# -*- coding: utf-8 -*-

# 1.为函数写一个装饰器，在函数执行之后输入 after
"""
def wrapper(func):
    def inner(*args, **kwargs):
        ret = func(*args, **kwargs)
        print('after')
        return ret
    return inner

@wrapper
def func():
    print(123)

func()
"""

# 2.为函数写一个装饰器，把函数的返回值 +100 然后再返回。
"""
def wrapper(func):
    def inner(*args, **kwargs):
        return func(*args, **kwargs) + 100
    return inner


@wrapper
def func():
    return 7

result = func()
print(result)
"""

# 3.为函数写一个装饰器，根据参数不同做不同操作。
# flag为True，则 让原函数执行后返回值加100，并返回。
# flag为False，则 让原函数执行后返回值减100，并返回。
"""
def x(TF):
    def wrapper(func):
        def inner(*args, **kwargs):
            ret = func(*args, **kwargs)
            if TF:
                return ret + 100
            else:
                return ret - 100
        return inner
    return wrapper


@x(True)
def f1():
    return 11

@x(False)
def f2():
    return 22

r1 = f1()
"""

# 5.递归的最大次数是多少？
"""
import sys

s1 = sys.getrecursionlimit()
print('最大的递归次数是%s次' % s1
"""

# 6.看代码写结果
"""
print("你\n好") 
# 你
# 好
print("你\\n好")
# 你n好
print(r"你\n好")
# 你\n好
"""

# 7.写函数实现，查看一个路径下所有的文件【所有】。
"""
import os


def check_the_path(path):
    result = os.walk(path)
    for a, b, c in result:
        for i in c:
            print(os.path.join(a, i))


check_the_path(r'G:\homework')
"""

# 8.写代码
# 请根据path找到code目录下所有的文件【单层】，并打印出来。
"""
import os

path = r"G:\code\test.pdf"
result = os.path.dirname(path)
print(os.listdir(result))
"""

# 9.写代码实现【题目1】和【题目2】
# 题目1
"""
COUNT = 0
def fibonacc(a, b):
    global COUNT
    if b > 4000000:
        print('这是第%s个斐波那契数' % COUNT)
        return
    print(b)
    COUNT += 1
    fibonacc(b, a + b)
fibonacc(0, 1)
"""

# 题目2
"""
dicta = {'a': 1, 'b': 2, 'c': 3, 'd': 4, 'f': 'hello'}
dictb = {'b': 3, 'd': 5, 'e': 7, 'm': 9, 'k': 'world'}
dictc = dict()
for k, v in dicta.items():
    if k not in dictc:
        dictc[k] = v
    else:
        dictc[k] = v + dicta[k]
for k, v in dictb.items():
    if k not in dictc:
        dictc[k] = v
    else:
        dictc[k] = v + dicta[k]
print(dictc)
"""

# 10.看代码写结果
"""
# list1 = [10]
# list2 = [123]
# list3 = [10, 'a']
"""

# 11.
# 1.
"""
B
"""

# 2.
"""
res = dict()
for i in range(0, len(tupleA)):
    res[tupleA[i]] = tupleB[i]
"""

# 3.
"""
import sys
path = sys.argv[1]
"""

# 4.
"""
ip_list = ip.split('.')
"""

# 5.
"""
AList = ','.join(AList)
"""

# 6.
"""
s1 = StrA[-2:]
s2 = StrA[1:3]
"""

# 7.
"""
s1 = Alist[:3]
"""

# 编程题
# 1.
"""
import os
def check_the_path(path):
    for a, b, c in os.path.dirname(path):
        for i in c:
            print(os.path.join(a, i))
"""

# 2.
"""
ls = list()
for i in range(1, 1001):
    ls1 = list()
    for count in range(1, i):
        a, b = divmod(i, count)
        if b == 0:
            ls1.append(count)
    total = 0
    for num in ls1:
        total += num
    if total == i:
        ls.append(i)
print(ls)
"""

# 5.
# with open('etl_log.txt', 'r', encoding='utf-8') as f:
#     for i in f:
#         print(i.strip())
